package com.tjetc.controller;

import com.tjetc.annotion.Log;
import com.tjetc.common.Result;
import com.tjetc.dao.NewsRepository;
import com.tjetc.dao.NewsTypeRepository;
import com.tjetc.domain.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/news")
public class NewsController {

    @Autowired
    private NewsTypeRepository newsTypeRepository;
    @Autowired
    private NewsRepository newsRepository;

    @RequestMapping("/list")
    @Log(model = "新闻",action = "获取新闻信息")
    public Result<?> getNewsList(){
        return Result.success("connection success!");
    }


    @RequestMapping("/findBySid")
    @Log(model = "新闻",action = "新闻分页查询")
    public Page<News> findSid(
            @RequestParam(defaultValue = "") Integer sid,
            @RequestParam(defaultValue = "1") Integer curPage,
            @RequestParam(defaultValue = "20") Integer pageSize
    ){
        PageRequest pageRequest = PageRequest.of(curPage - 1, pageSize);
        Page <News> page=newsRepository.findBySid(pageRequest,sid);
        return page;
    }


    @RequestMapping("/findBySid1")
    @Log(model = "新闻",action = "查询公告")
    public List findBySid1(
            @RequestParam(defaultValue = "1") Integer sid
    ){
        return newsRepository.findBySid(sid);
    }
    @RequestMapping("/findBySid2")
    @Log(model = "新闻",action = "查询资讯")
    public List findBySid2(
            @RequestParam(defaultValue = "2") Integer sid
    ){
        return newsRepository.findBySid(sid);
    }
}
